import i18n from '../i18n/index'
import store from '../store/index'

// auth 认证  管理本地的 token认证信息
// const AUTH_KEY = 'local-token'
const LANG = 'evst-platform-LANG'
const TABS = 'evst-platform-TABS'
// // 获取用户信息
// export const getToken = () => {
//   return JSON.parse(window.localStorage.getItem(AUTH_KEY) || '{}')
// }
// // 设置用户信息 user 对象格式
// export const setToken = (user) => {
//   window.localStorage.setItem(AUTH_KEY, JSON.stringify(user))
// }
// // 删除用户信息
// export const delToken = () => {
//   window.localStorage.removeItem(AUTH_KEY)
// }


export const setLang = (lang) => {
  window.sessionStorage.setItem(LANG, JSON.stringify(lang))
}

export const localSave = (key, value) => {
  window.sessionStorage.setItem(key, value)
}

export const localRead = (key) => {
  return sessionStorage.getItem(key) || ''
}

// 获取tabs标签
// export const getTabs = () => {
//   return JSON.parse(window.sessionStorage.getItem(TABS) || '[]')
// }

// 设置tabs标签
export const setTabs = (tab) => {
  window.sessionStorage.setItem((TABS), JSON.stringify(tab))
}

// 删除tabs标签
export const delTabs = () => {
  window.sessionStorage.removeItem(TABS)
}

export const swichLang = (langKey) => {
  const cnLang = i18n.messages.简体中文
  const enLang = i18n.messages.English
  if (i18n.locale === '简体中文') {
    for (const i in cnLang) {
      for (const j in cnLang[i]) {
        if (langKey === j) {
          return cnLang[i][j]
        }
      }
    }
  } else {
    for (const n in enLang) {
      for (const m in enLang[n]) {
        if (langKey === m) {
          return enLang[n][m]
        }
      }
    }
  }
}

export const swichLangInValue = (langValue) => {
  const cnLang = i18n.messages.简体中文
  for (const i in cnLang) {
    for (const j in cnLang[i]) {
      if (langValue === cnLang[i][j]) {
        return j
      }
    }
  }
}

export const isHasAuth = (resList, code) => {
  if (resList && resList.includes(code)) {
    return true
  } else {
    return false
  }
}
